<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAreasTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('areas', function (Blueprint $table){
            $table->increments('id');
            $table->unsignedInteger('parent_id')->comment('父ID');
            $table->tinyInteger('level', false, true)->default(0)->comment('层级');
            $table->string('area_code', 12)->unique()->default('0')->comment('行政代码');
            $table->char('zip_code', 6)->default('000000')->comment('邮编');
            $table->char('city_code', 6)->default('')->comment('区号');
            $table->string('name', 50)->comment('名称');
            $table->string('short_name', 50)->comment('简称');
            $table->string('merger_name', 50)->comment('组合名');
            $table->string('pinyin', 50)->comment('拼音');
            $table->decimal('lng', 10, 6)->default('0.000000')->comment('经度');
            $table->decimal('lat', 10, 6)->default('0.000000')->comment('维度');
            $table->index(['level', 'parent_id']);
            $table->engine = 'MyISAM';
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('areas');
    }
}
